package per.sunmes.lesrb.cus;

import java.io.IOException;

import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.ImageResolver;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;

import per.sunmes.lesrb.manager.RM;

public class TmxMapLoaderWithCustomRes extends TmxMapLoader {

	ImageResolver imgResolver;

	public TmxMapLoaderWithCustomRes() {
		super(RM.getFileHandleResolver());
		imgResolver = new EmptyImageResolver();
	}

	public TmxMapLoaderWithCustomRes(ImageResolver customImageResolver) {
		super(RM.getFileHandleResolver());
		imgResolver = customImageResolver;
	}

	@Override
	public TiledMap load(String fileName) {
		try {
			root = xml.parse(RM.getFile(fileName));
			map = loadTilemap(root, RM.getFile(fileName), imgResolver);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map;
	}

	//////
	public class EmptyImageResolver implements ImageResolver {
		TextureRegion region = new TextureRegion(RM.getWhiteRectTexture(), 0, 0, 2048, 2048);

		@Override
		public TextureRegion getImage(String name) {
			return region;
		}
	}

}
